define(function(require, exports, module) {
    var template = require("template");
    var Ajax = require("ajax");
        require("animations");
        require("css/publicDom.css");
    var Q = require("Q");
    var layer = require("layer");
    var publicDom = function(callback){
        this.init.apply(this,arguments);
    }
    publicDom.prototype = {
        constructor : publicDom,
        options:{

        },
        init : function(callback,options){
            var t = this;
            t.analysisPage=false;
            this.options = $.extend({},t.options,options);
            t.isLoading();
            require.async(["templates/publicDom.html"],function(html){
                $("#base_wrap").html(html);
            });
            typeof callback == "function" && callback();
            t.bindClick();
            t.weixinStorage();
        },
//        loadUserInfo:function(){
//       	 	Ajax.ajax({
//                url:localhost + "user/selectByPrimaryKey",
//                success:function(data){
//                	$("#userCount").html(data.data.userAccount);
//                	if(data.data.userPermission==1){
//                		$("#userAdmin").css('display','block');
//                	}else{
//                		$("#userAdmin").css('display','none');
//                	}
//                }
//           });
//       },
       isLoading:function(){
		   Ajax.ajax({
			   url: localhost+"login/logined.do",
			   success: function (data) {
				   if(data.returnCode == 10000){
					   $(".centerBox").remove();
					   var s = 2;
					   function run() {
						   s -= 1;
						   if(s >= 0) $(".theInSecond").html(s);
					   }
					   if(window.location.href.indexOf("index/login")>-1) {
						   layer.msg("您已登录！<strong class='theInSecond'>" + s + "</strong> 秒后前往首页...");
						   setInterval(run, 1000);
						   setTimeout(function(){
							   window.location.href=localhost+('views/admin.jsp#!admin/home');
	                       },3000);
					   }
				   }
               }
           });
       },
       bindClick:function(){
    	   $("#doLoginOut").on("click",function(){
    		   Ajax.ajax({
    			   url: localhost+"login/logout.do",
    			   success: function (data) {
    				   if (data.returnCode==10000) {
    		               layer.msg("退出成功！");
    		               setTimeout(function(){
							   window.location.href=localhost+('views/index.jsp#!index/login');
	                       },1000);
    		           }
                   }
               });
    	   });
       	},
        weixinStorage:function(){
        	for (var key in localStorage){
            	if (new Date().valueOf()-60*60*24*7*1000 > parseInt(localStorage.getItem(key))) {
            	    localStorage.removeItem(key);    //对超过7天的localStorage的微信articleId进行清除
            	}
        	}
        }
   }
   module.exports = publicDom;
});
